// 抽象类 Animal
abstract class Animal {
    // 基本属性
    protected String name;
    protected String type;
    protected String breed;
    protected double price;

    // 构造方法
    public Animal(String name, String type, String breed, double price) {
        this.name = name;
        this.type = type;
        this.breed = breed;
        this.price = price;
    }

    // 抽象方法：吃饭
    public abstract void eat();

    // 抽象方法：睡觉
    public abstract void sleep();

    // 抽象方法：玩
    public abstract void play();

    // 抽象方法：叫
    public abstract void bark();
}

// 猫类 Cat 继承 Animal
class Cat extends Animal {
    private boolean isPlaying;

    // 构造方法
    public Cat(String name, String breed, double price) {
        super(name, "Cat", breed, price);
        this.isPlaying = false;
    }

    // 吃饭方法
    @Override
    public void eat() {
        System.out.println(name + " is eating.");
    }

    // 睡觉方法
    @Override
    public void sleep() {
        System.out.println(name + " is sleeping.");
    }

    // 玩的方法
    @Override
    public void play() {
        System.out.println(name + " is playing.");
        isPlaying = true;
    }

    // 叫的方法，只有在玩的时候才会叫
    @Override
    public void bark() {
        if (isPlaying) {
            System.out.println(name + " says meow.");
        } else {
            System.out.println(name + " is not playing, so it doesn't meow.");
        }
    }
}

// 狗类 Dog 继承 Animal
class Dog extends Animal {
    // 构造方法
    public Dog(String name, String breed, double price) {
        super(name, "Dog", breed, price);
    }

    // 吃饭方法
    @Override
    public void eat() {
        System.out.println(name + " is eating.");
    }

    // 睡觉方法
    @Override
    public void sleep() {
        System.out.println(name + " is sleeping.");
    }

    // 玩的方法
    @Override
    public void play() {
        System.out.println(name + " is playing.");
    }

    // 叫的方法，狗可以随时叫
    @Override
    public void bark() {
        System.out.println(name + " says woof.");
    }
}

// 测试类
public class Main {
    public static void main(String[] args) {
        // 创建猫和狗对象
        Animal cat = new Cat("Tom", "Persian", 1000.0);
        Animal dog = new Dog("Buddy", "Golden Retriever", 1500.0);

        // 调用猫类的方法
        System.out.println("Cat actions:");
        cat.eat();
        cat.sleep();
        cat.play();
        cat.bark();

        // 调用狗类的方法
        System.out.println("\nDog actions:");
        dog.eat();
        dog.sleep();
        dog.play();
        dog.bark();
    }
}
